﻿@namespace Masa.Docs.Shared.Components
@inject I18n I18n

<MNavigationDrawer Value="Value"
                   ValueChanged="ValueChanged"
                   Class="pt-2"
                   Width="240"
                   Right
                   Fixed
                   Floating
                   Temporary>
    <MList Nav>
        <MListItemGroup>
            @foreach (var item in _items)
            {
                <MListItem Href="@item.Href" Target="@item.Target">
                    <MListItemContent>
                        <MListItemTitle Class="d-flex align-center justify-space-between">
                            @I18n.T(item.Title)
                            @if (!string.IsNullOrWhiteSpace(item.State))
                            {
                                <MChip Color="@item.StateBackgroundColor" Small>@I18n.T(item.State)</MChip>
                            }
                        </MListItemTitle>
                    </MListItemContent>
                </MListItem>
            }
            <MDivider/>
            <MListItem Href="https://github.com/masastack/MASA.Blazor" Target="_blank">
                <MListItemContent>
                    <MListItemTitle>Github</MListItemTitle>
                </MListItemContent>
            </MListItem>
            <MListItem Href="https://gitee.com/blazorcomponent/MASA.Blazor" Target="_blank">
                <MListItemContent>
                    <MListItemTitle>Gitee</MListItemTitle>
                </MListItemContent>
            </MListItem>
        </MListItemGroup>
    </MList>
</MNavigationDrawer>

@code {

    [CascadingParameter(Name = "project")] public string? Project { get; set; }

    [Parameter] public bool? Value { get; set; }

    [Parameter] public EventCallback<bool?> ValueChanged { get; set; }

    private List<DefaultItem> _items = new();

    private string? _prevProject;

    protected override void OnInitialized()
    {
        base.OnInitialized();

        RefreshItems();
    }

    protected override void OnParametersSet()
    {
        base.OnParametersSet();

        if (_prevProject != Project)
        {
            _prevProject = Project;
            RefreshItems();
        }
    }

    private void RefreshItems()
    {
        _items.Clear();
        _items.AddRange(AppService.GetNavMenus(Project));
        _items.AddRange(AppService.GetResources(Project));
    }

}